home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 October: Mac OS SDK / Dev.CD Oct 00 SDK1.toast / Development Kits / Cross Platform / QuickTime 4.1.2 Windows SDK / CIncludes / Multiprocessing.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-04-12  |  28.7 KB  |  957 lines  |  [TEXT/R*ch]

  1. /*
  2.      File:        Multiprocessing.h
  3.  
  4.      Contains:    Multiprocessing interfaces
  5.  
  6.      Version:    Technology:    Multiprocessing API version 2.0, integrated nanokernel support
  7.                  Release:    QuickTime 4.1
  8.  
  9.      Copyright:    (c) 1996-1999 by Apple Computer, Inc. and (c) 1995-1997 DayStar Digital, Inc.
  10.  
  11.      Bugs?:        For bug reports, consult the following page on
  12.                  the World Wide Web:
  13.  
  14.                      http://developer.apple.com/bugreporter/
  15.  
  16. */
  17.  
  18. /*
  19.    ===========================================================================================
  20.    *** WARNING: You must properly check the availability of MP services before calling them!
  21.    See the section titled "Checking API Availability".
  22.    ===========================================================================================
  23. */
  24.  
  25.  
  26. #ifndef __MULTIPROCESSING__
  27. #define __MULTIPROCESSING__
  28.  
  29. #ifndef __MACTYPES__
  30.     #include <MacTypes.h>
  31. #endif
  32.  
  33. #ifndef __CODEFRAGMENTS__
  34.     #include <CodeFragments.h>
  35. #endif
  36.  
  37.  
  38. #ifndef __DRIVERSERVICES__
  39.     #include <DriverServices.h>
  40. #endif
  41.  
  42.  
  43.  
  44.  
  45.  
  46. #if PRAGMA_ONCE
  47. #pragma once
  48. #endif
  49.  
  50. #ifdef __cplusplus
  51. extern "C" {
  52. #endif
  53.  
  54. #if PRAGMA_IMPORT
  55. #pragma import on
  56. #endif
  57.  
  58. #if PRAGMA_STRUCT_ALIGN
  59.     #pragma options align=power
  60. #elif PRAGMA_STRUCT_PACKPUSH
  61.     #pragma pack(push, 2)
  62. #elif PRAGMA_STRUCT_PACK
  63.     #pragma pack(2)
  64. #endif
  65.  
  66. /*
  67.    ===========================================================================================
  68.    This is the header file for version 2.0 of the Mac OS multiprocessing support.  This version
  69.    has been totally reimplemented and has significant new services.  The main goal of the
  70.    reimplementation has been to transfer task management into the core operating system to provide
  71.    much more reliable and more efficient operation, including on single processor machines.
  72.    The memory management has also been massively improved, it is much faster and wastes much
  73.    less space.  New services include POSIX style per-task storage, timers with millisecond and
  74.    microsecond resolutions, memory allocation at a specified alignment, and system pageable
  75.    and RAM resident memory pools.  See the MP API documentation for details.
  76.    The old "DayStar" debugging services (whose names began with an underscore) have been
  77.    removed from this header.  A very few are still implemented for binary compatibility, or in
  78.    cases where they happened to be exposed inappropriately.  (E.g. _MPIsFullyInitialized must
  79.    be called to see if the MP API is ReallyTruly(tm) usable.)  New code and recompiles of old
  80.    code should avoid use of these defunct services, except for _MPIsFullyInitialized.
  81.    ===========================================================================================
  82. */
  83.  
  84.  
  85. /*
  86.    ===========================================================================================
  87.    The following services are from the original MP API and remain supported in version 2.0:
  88.       MPProcessors
  89.       MPCreateTask
  90.       MPTerminateTask
  91.       MPCurrentTaskID
  92.       MPYield
  93.       MPExit
  94.       MPCreateQueue
  95.       MPDeleteQueue
  96.       MPNotifyQueue
  97.       MPWaitOnQueue
  98.       MPCreateSemaphore
  99.       MPCreateBinarySemaphore        (In C only, a macro that calls MPCreateSemaphore.)
  100.       MPDeleteSemaphore
  101.       MPSignalSemaphore
  102.       MPWaitOnSemaphore
  103.       MPCreateCriticalRegion
  104.       MPDeleteCriticalRegion
  105.       MPEnterCriticalRegion
  106.       MPExitCriticalRegion
  107.       MPAllocate                    (Deprecated, use MPAllocateAligned for new builds.)
  108.       MPFree
  109.       MPBlockCopy
  110.       MPLibraryIsLoaded            (In C only, a macro.)
  111.       _MPIsFullyInitialized        (See comments about checking for MP API availability.)
  112.    ===========================================================================================
  113. */
  114.  
  115.  
  116. /*
  117.    ===========================================================================================
  118.    The following services are new in version 2.0:
  119.       MPProcessorsScheduled
  120.       MPSetTaskWeight
  121.       MPTaskIsPreemptive
  122.       MPAllocateTaskStorageIndex
  123.       MPDeallocateTaskStorageIndex
  124.       MPSetTaskStorageValue
  125.       MPGetTaskStorageValue
  126.       MPSetQueueReserve
  127.       MPCreateEvent
  128.       MPDeleteEvent
  129.       MPSetEvent
  130.       MPWaitForEvent
  131.       UpTime
  132.       DurationToAbsolute
  133.       AbsoluteToDuration
  134.       MPDelayUntil
  135.       MPCreateTimer
  136.       MPDeleteTimer
  137.       MPSetTimerNotify
  138.       MPArmTimer
  139.       MPCancelTimer
  140.       MPSetExceptionHandler
  141.       MPThrowException
  142.       MPDisposeTaskException
  143.       MPExtractTaskState
  144.       MPSetTaskState
  145.       MPRegisterDebugger
  146.       MPUnregisterDebugger
  147.       MPAllocateAligned            (Preferred over MPAllocate.)
  148.       MPGetAllocatedBlockSize
  149.       MPBlockClear
  150.       MPDataToCode
  151.       MPRemoteCall                (Preferred over _MPRPC.)
  152.    ===========================================================================================
  153. */
  154.  
  155.  
  156. /*
  157.    ===========================================================================================
  158.    The following services are new in version 2.1:
  159.       MPCreateNotification
  160.       MPDeleteNotification
  161.       MPModifyNotification
  162.       MPCauseNotification
  163.       MPGetNextTaskID
  164.       MPGetNextCpuID
  165.    ===========================================================================================
  166. */
  167.  
  168.  
  169. /*
  170.    ===========================================================================================
  171.    The following services are "unofficial" extensions to the original API.  They are not in
  172.    the multiprocessing API documentation, but were in previous versions of this header.  They
  173.    remain supported in version 2.0.  They may not be supported in other environments.
  174.       _MPRPC                        (Deprecated, use MPRemoteCall for new builds.)
  175.       _MPAllocateSys                (Deprecated, use MPAllocateAligned for new builds.)
  176.       _MPTaskIsToolboxSafe
  177.       _MPLibraryVersion
  178.       _MPLibraryIsCompatible
  179.    ===========================================================================================
  180. */
  181.  
  182.  
  183. /*
  184.    ===========================================================================================
  185.    The following services were in previous versions of this header for "debugging only" use.
  186.    They are NOT implemented in version 2.0.  For old builds they can be accessed by defining
  187.    the symbol MPIncludeDefunctServices to have a nonzero value.
  188.       _MPInitializePrintf
  189.       _MPPrintf
  190.       _MPDebugStr
  191.       _MPStatusPString
  192.       _MPStatusCString
  193.    ===========================================================================================
  194. */
  195.  
  196.  
  197. /*
  198.    .
  199.    ===========================================================================================
  200.    General Types and Constants
  201.    ===========================
  202. */
  203.  
  204.  
  205. #define MPCopyrightNotice    \
  206.     "Copyright © 1995-1999 Apple Computer, Inc.\n"
  207. #define MPLibraryName "MPLibrary"
  208. #define MPLibraryCName MPLibraryName
  209. #define MPLibraryPName "\p" MPLibraryName
  210. #define MP_API_Version "2.1"
  211.  
  212. enum {
  213.     MPLibrary_MajorVersion        = 2,
  214.     MPLibrary_MinorVersion        = 1,
  215.     MPLibrary_Release            = 1,
  216.     MPLibrary_DevelopmentRevision = 1
  217. };
  218.  
  219.  
  220. typedef CFragContextID                     MPProcessID;
  221. typedef struct OpaqueMPTaskID*             MPTaskID;
  222. typedef struct OpaqueMPQueueID*         MPQueueID;
  223. typedef struct OpaqueMPSemaphoreID*     MPSemaphoreID;
  224. typedef struct OpaqueMPCriticalRegionID*  MPCriticalRegionID;
  225. typedef struct OpaqueMPTimerID*         MPTimerID;
  226. typedef struct OpaqueMPEventID*         MPEventID;
  227. typedef struct OpaqueMPAddressSpaceID*     MPAddressSpaceID;
  228. typedef struct OpaqueMPNotificationID*     MPNotificationID;
  229. typedef struct OpaqueMPCoherenceID*     MPCoherenceID;
  230. typedef struct OpaqueMPCpuID*             MPCpuID;
  231. typedef struct OpaqueMPOpaqueID*         MPOpaqueID;
  232. enum {
  233.     kMPNoID                        = kInvalidID                    /* New code should use kInvalidID everywhere.*/
  234. };
  235.  
  236.  
  237. typedef OptionBits                         MPTaskOptions;
  238. typedef UInt32                             TaskStorageIndex;
  239. typedef UInt32                             TaskStorageValue;
  240. typedef ItemCount                         MPSemaphoreCount;
  241. typedef UInt32                             MPTaskWeight;
  242. typedef UInt32                             MPEventFlags;
  243. typedef UInt32                             MPExceptionKind;
  244. typedef UInt32                             MPTaskStateKind;
  245. typedef UInt32                             MPDebuggerLevel;
  246. enum {
  247.     kDurationImmediate            = 0L,
  248.     kDurationForever            = 0x7FFFFFFF,
  249.     kDurationMillisecond        = 1,
  250.     kDurationMicrosecond        = -1
  251. };
  252.  
  253.  
  254. /*
  255.    .
  256.    ===========================================================================================
  257.    Tasking Services
  258.    ================
  259. */
  260.  
  261.  
  262. EXTERN_API_C( ItemCount )
  263. MPProcessors                    (void);
  264.  
  265. /* The physical total.*/
  266. EXTERN_API_C( ItemCount )
  267. MPProcessorsScheduled            (void);
  268.  
  269. /* Those currently in use.*/
  270. EXTERN_API_C( OSStatus )
  271. MPGetNextCpuID                    (MPCoherenceID             owningCoherenceID,
  272.                                  MPCpuID *                cpuID);
  273.  
  274.  
  275. enum {
  276.                                                                 /* For MPCreateTask options*/
  277.     kMPCreateTaskTakesAllExceptionsMask = 1L << 1,
  278.     kMPCreateTaskValidOptionsMask = kMPCreateTaskTakesAllExceptionsMask
  279. };
  280.  
  281. /* -------------------------------------------------------------------------------------------*/
  282.  
  283.  
  284. typedef CALLBACK_API_C( OSStatus , TaskProc )(void *parameter);
  285. EXTERN_API_C( OSStatus )
  286. MPCreateTask                    (TaskProc                 entryPoint,
  287.                                  void *                    parameter,
  288.                                  ByteCount                 stackSize,
  289.                                  MPQueueID                 notifyQueue,
  290.                                  void *                    terminationParameter1,
  291.                                  void *                    terminationParameter2,
  292.                                  MPTaskOptions             options,
  293.                                  MPTaskID *                task);
  294.  
  295. EXTERN_API_C( OSStatus )
  296. MPTerminateTask                    (MPTaskID                 task,
  297.                                  OSStatus                 terminationStatus);
  298.  
  299. EXTERN_API_C( OSStatus )
  300. MPSetTaskWeight                    (MPTaskID                 task,
  301.                                  MPTaskWeight             weight);
  302.  
  303. EXTERN_API_C( Boolean )
  304. MPTaskIsPreemptive                (MPTaskID                 taskID);
  305.  
  306. /* May be kInvalidID.*/
  307. EXTERN_API_C( void )
  308. MPExit                            (OSStatus                 status);
  309.  
  310. EXTERN_API_C( void )
  311. MPYield                            (void);
  312.  
  313. EXTERN_API_C( MPTaskID )
  314. MPCurrentTaskID                    (void);
  315.  
  316. EXTERN_API_C( OSStatus )
  317. MPGetNextTaskID                    (MPProcessID             owningProcessID,
  318.                                  MPTaskID *                taskID);
  319.  
  320.  
  321. /* -------------------------------------------------------------------------------------------*/
  322.  
  323.  
  324. /*
  325.    ---------------------------------------------------
  326.    ! The task storage services are new in version 2.0.
  327. */
  328.  
  329.  
  330. EXTERN_API_C( OSStatus )
  331. MPAllocateTaskStorageIndex        (TaskStorageIndex *        index);
  332.  
  333. EXTERN_API_C( OSStatus )
  334. MPDeallocateTaskStorageIndex    (TaskStorageIndex         index);
  335.  
  336. EXTERN_API_C( OSStatus )
  337. MPSetTaskStorageValue            (TaskStorageIndex         index,
  338.                                  TaskStorageValue         value);
  339.  
  340. EXTERN_API_C( TaskStorageValue )
  341. MPGetTaskStorageValue            (TaskStorageIndex         index);
  342.  
  343.  
  344. /*
  345.    .
  346.    ===========================================================================================
  347.    Synchronization Services
  348.    ========================
  349. */
  350.  
  351.  
  352. EXTERN_API_C( OSStatus )
  353. MPCreateQueue                    (MPQueueID *            queue);
  354.  
  355. EXTERN_API_C( OSStatus )
  356. MPDeleteQueue                    (MPQueueID                 queue);
  357.  
  358. EXTERN_API_C( OSStatus )
  359. MPNotifyQueue                    (MPQueueID                 queue,
  360.                                  void *                    param1,
  361.                                  void *                    param2,
  362.                                  void *                    param3);
  363.  
  364. EXTERN_API_C( OSStatus )
  365. MPWaitOnQueue                    (MPQueueID                 queue,
  366.                                  void **                param1,
  367.                                  void **                param2,
  368.                                  void **                param3,
  369.                                  Duration                 timeout);
  370.  
  371. EXTERN_API_C( OSStatus )
  372. MPSetQueueReserve                (MPQueueID                 queue,
  373.                                  ItemCount                 count);
  374.  
  375.  
  376. /* -------------------------------------------------------------------------------------------*/
  377.  
  378.  
  379. EXTERN_API_C( OSStatus )
  380. MPCreateSemaphore                (MPSemaphoreCount         maximumValue,
  381.                                  MPSemaphoreCount         initialValue,
  382.                                  MPSemaphoreID *        semaphore);
  383.  
  384. EXTERN_API_C( OSStatus )
  385. MPDeleteSemaphore                (MPSemaphoreID             semaphore);
  386.  
  387. EXTERN_API_C( OSStatus )
  388. MPSignalSemaphore                (MPSemaphoreID             semaphore);
  389.  
  390. EXTERN_API_C( OSStatus )
  391. MPWaitOnSemaphore                (MPSemaphoreID             semaphore,
  392.                                  Duration                 timeout);
  393.  
  394.  
  395. #define MPCreateBinarySemaphore(semaphore)    \
  396.             MPCreateSemaphore ( 1, 1, (semaphore) )
  397.  
  398. /* -------------------------------------------------------------------------------------------*/
  399.  
  400.  
  401. EXTERN_API_C( OSStatus )
  402. MPCreateCriticalRegion            (MPCriticalRegionID *    criticalRegion);
  403.  
  404. EXTERN_API_C( OSStatus )
  405. MPDeleteCriticalRegion            (MPCriticalRegionID     criticalRegion);
  406.  
  407. EXTERN_API_C( OSStatus )
  408. MPEnterCriticalRegion            (MPCriticalRegionID     criticalRegion,
  409.                                  Duration                 timeout);
  410.  
  411. EXTERN_API_C( OSStatus )
  412. MPExitCriticalRegion            (MPCriticalRegionID     criticalRegion);
  413.  
  414.  
  415. /* -------------------------------------------------------------------------------------------*/
  416.  
  417. EXTERN_API( OSStatus )
  418. MPCreateEvent                    (MPEventID *            event);
  419.  
  420. EXTERN_API_C( OSStatus )
  421. MPDeleteEvent                    (MPEventID                 event);
  422.  
  423. EXTERN_API_C( OSStatus )
  424. MPSetEvent                        (MPEventID                 event,
  425.                                  MPEventFlags             flags);
  426.  
  427. EXTERN_API( OSStatus )
  428. MPWaitForEvent                    (MPEventID                 event,
  429.                                  MPEventFlags *            flags,
  430.                                  Duration                 timeout);
  431.  
  432. /*
  433.    .
  434.    ===========================================================================================
  435.    Notification Services (API)
  436.    =====================
  437. */
  438.  
  439.  
  440. EXTERN_API_C( OSStatus )
  441. MPCreateNotification            (MPNotificationID *        notificationID);
  442.  
  443. /* -------------------------------------------------------------------------------------------*/
  444.  
  445. EXTERN_API_C( OSStatus )
  446. MPDeleteNotification            (MPNotificationID         notificationID);
  447.  
  448. /* -------------------------------------------------------------------------------------------*/
  449.  
  450. EXTERN_API_C( OSStatus )
  451. MPModifyNotification            (MPNotificationID         notificationID,
  452.                                  MPOpaqueID             anID,
  453.                                  void *                    notifyParam1,
  454.                                  void *                    notifyParam2,
  455.                                  void *                    notifyParam3);
  456.  
  457. /* -------------------------------------------------------------------------------------------*/
  458.  
  459. EXTERN_API_C( OSStatus )
  460. MPCauseNotification                (MPNotificationID         notificationID);
  461.  
  462. /*
  463.    .
  464.    ===========================================================================================
  465.    Timer Services
  466.    ==============
  467. */
  468.  
  469.  
  470. /*
  471.    --------------------------------------------
  472.    ! The timer services are new in version 2.0.
  473. */
  474.  
  475.  
  476. #if 0
  477. /* For now these are taken from DriverServices, should be in a better place.*/
  478. EXTERN_API_C( AbsoluteTime )
  479. UpTime                            (void);
  480.  
  481. EXTERN_API_C( AbsoluteTime )
  482. DurationToAbsolute                (Duration                 duration);
  483.  
  484. EXTERN_API_C( Duration )
  485. AbsoluteToDuration                (AbsoluteTime             time);
  486.  
  487. #endif  /* 0 */
  488.  
  489. enum {
  490.                                                                 /* For MPArmTimer options*/
  491.     kMPPreserveTimerIDMask        = 1L << 0,
  492.     kMPTimeIsDeltaMask            = 1L << 1,
  493.     kMPTimeIsDurationMask        = 1L << 2
  494. };
  495.  
  496.  
  497. EXTERN_API_C( OSStatus )
  498. MPDelayUntil                    (AbsoluteTime *            expirationTime);
  499.  
  500. EXTERN_API_C( OSStatus )
  501. MPCreateTimer                    (MPTimerID *            timerID);
  502.  
  503. EXTERN_API_C( OSStatus )
  504. MPDeleteTimer                    (MPTimerID                 timerID);
  505.  
  506. EXTERN_API_C( OSStatus )
  507. MPSetTimerNotify                (MPTimerID                 timerID,
  508.                                  MPOpaqueID             anID,
  509.                                  void *                    notifyParam1,
  510.                                  void *                    notifyParam2,
  511.                                  void *                    notifyParam3);
  512.  
  513. EXTERN_API_C( OSStatus )
  514. MPArmTimer                        (MPTimerID                 timerID,
  515.                                  AbsoluteTime *            expirationTime,
  516.                                  OptionBits             options);
  517.  
  518. EXTERN_API_C( OSStatus )
  519. MPCancelTimer                    (MPTimerID                 timerID,
  520.                                  AbsoluteTime *            timeRemaining);
  521.  
  522.  
  523. /*
  524.    .
  525.    ===========================================================================================
  526.    Memory Services
  527.    ===============
  528. */
  529.  
  530.  
  531. enum {
  532.                                                                 /* Maximum allocation request size is 1GB.*/
  533.     kMPMaxAllocSize                = 1024L * 1024 * 1024
  534. };
  535.  
  536. enum {
  537.                                                                 /* Values for the alignment parameter to MPAllocateAligned.*/
  538.     kMPAllocateDefaultAligned    = 0,
  539.     kMPAllocate8ByteAligned        = 3,
  540.     kMPAllocate16ByteAligned    = 4,
  541.     kMPAllocate32ByteAligned    = 5,
  542.     kMPAllocate1024ByteAligned    = 10,
  543.     kMPAllocate4096ByteAligned    = 12,
  544.     kMPAllocateMaxAlignment        = 16,                            /* Somewhat arbitrary limit on expectations.*/
  545.     kMPAllocateAltiVecAligned    = kMPAllocate16ByteAligned,        /* The P.C. name.*/
  546.     kMPAllocateVMXAligned        = kMPAllocateAltiVecAligned,    /* The older, common name.*/
  547.     kMPAllocateVMPageAligned    = 254,                            /* Pseudo value, converted at runtime.*/
  548.     kMPAllocateInterlockAligned    = 255                            /* Pseudo value, converted at runtime.*/
  549. };
  550.  
  551. enum {
  552.                                                                 /* Values for the options parameter to MPAllocateAligned.*/
  553.     kMPAllocateClearMask        = 0x0001,                        /* Zero the allocated block.*/
  554.     kMPAllocateGloballyMask        = 0x0002,                        /* Allocate from the globally visible pool.*/
  555.     kMPAllocateResidentMask        = 0x0004,                        /* Allocate from the RAM-resident pool.*/
  556.     kMPAllocateNoGrowthMask        = 0x0010                        /* Do not attempt to grow the pool.*/
  557. };
  558.  
  559.  
  560. /* -------------------------------------------------------------------------------------------*/
  561.  
  562.  
  563. EXTERN_API_C( LogicalAddress )
  564. MPAllocateAligned                (ByteCount                 size,
  565.                                  UInt8                     alignment,
  566.                                  OptionBits             options);
  567.  
  568. /* ! MPAllocateAligned is new in version 2.0.*/
  569. EXTERN_API_C( LogicalAddress )
  570. MPAllocate                        (ByteCount                 size);
  571.  
  572. /* Use MPAllocateAligned instead.*/
  573. EXTERN_API_C( void )
  574. MPFree                            (LogicalAddress         object);
  575.  
  576. EXTERN_API_C( ByteCount )
  577. MPGetAllocatedBlockSize            (LogicalAddress         object);
  578.  
  579. /* -------------------------------------------------------------------------------------------*/
  580.  
  581.  
  582. EXTERN_API_C( void )
  583. MPBlockCopy                        (LogicalAddress         source,
  584.                                  LogicalAddress         destination,
  585.                                  ByteCount                 size);
  586.  
  587. EXTERN_API_C( void )
  588. MPBlockClear                    (LogicalAddress         address,
  589.                                  ByteCount                 size);
  590.  
  591. /* ! MPBlockClear is new in version 2.0.*/
  592. EXTERN_API_C( void )
  593. MPDataToCode                    (LogicalAddress         address,
  594.                                  ByteCount                 size);
  595.  
  596. /* ! MPDataToCode is new in version 2.0.*/
  597. /*
  598.    .
  599.    ===========================================================================================
  600.    Exception/Debugging Services
  601.    ============================
  602. */
  603.  
  604.  
  605. /*
  606.    -------------------------------------------------------------------------------------------
  607.    *** Important Note ***
  608.    ----------------------
  609.    
  610.    The functions MPExtractTaskState and MPSetTaskState infer the size of the "info" buffer
  611.    from the "kind" parameter.  A given value for MPTaskStateKind will always refer to a
  612.    single specific physical buffer layout.  Should new register sets be added, or the size
  613.    or number of any registers change, new values of MPTaskStateKind will be introduced to
  614.    refer to the new buffer layouts.
  615.    
  616.    The following types for the buffers are in MachineExceptions. The correspondence between
  617.    MPTaskStateKind values and MachineExceptions types is:
  618.    
  619.           kMPTaskStateRegisters                -> RegisterInformation
  620.           kMPTaskStateFPU                        -> FPUInformation
  621.           kMPTaskStateVectors                    -> VectorInformation
  622.           kMPTaskStateMachine                    -> MachineInformation
  623.           kMPTaskState32BitMemoryException    -> ExceptionInfo for old-style 32-bit memory exceptions
  624.    
  625.       For reference, on PowerPC the MachineExceptions types contain:
  626.    
  627.           RegisterInformation    -> The GPRs, 32 values of 64 bits each.
  628.           FPUInformation        -> The FPRs plus FPSCR, 32 values of 64 bits each, one value of
  629.                                   32 bits.
  630.           VectorInformation    -> The AltiVec vector registers plus VSCR and VRSave, 32 values
  631.                                   of 128 bits each, one value of 128 bits, and one 32 bit value.
  632.           MachineInformation    -> The CTR, LR, PC, each of 64 bits.  The CR, XER, MSR, MQ,
  633.                                   exception kind, and DSISR, each of 32 bits.  The 64 bit DAR.
  634.           ExceptionInfo        -> Only memory exceptions are specified, 4 fields of 32 bits each.
  635.                                   Note that this type only covers memory exceptions on 32-bit CPUs!
  636. */
  637. /*
  638.    The following types are declared here:
  639.           kMPTaskStateTaskInfo                -> MPTaskInfo
  640. */
  641. enum {
  642.                                                                 /* Values for the TaskStateKind to MPExtractTaskState and MPSetTaskState.*/
  643.     kMPTaskStateRegisters        = 0,                            /* The task general registers.*/
  644.     kMPTaskStateFPU                = 1,                            /* The task floating point registers*/
  645.     kMPTaskStateVectors            = 2,                            /* The task vector registers*/
  646.     kMPTaskStateMachine            = 3,                            /* The task machine registers*/
  647.     kMPTaskState32BitMemoryException = 4                        /* The task memory exception information for 32-bit CPUs.*/
  648. };
  649.  
  650. enum {
  651.     kMPTaskStateTaskInfo        = 5                                /* Static and dynamic information about the task.*/
  652. };
  653.  
  654. enum {
  655.                                                                 /* Option bits and numbers for MPDisposeTaskException.*/
  656.     kMPTaskPropagate            = 0,                            /* The exception is propagated.*/
  657.     kMPTaskResumeStep            = 1,                            /* The task is resumed and single step is enabled.*/
  658.     kMPTaskResumeBranch            = 2,                            /* The task is resumed and branch stepping is enabled.*/
  659.     kMPTaskResumeMask            = 0x0000,                        /* The task is resumed.*/
  660.     kMPTaskPropagateMask        = 1 << kMPTaskPropagate,        /* The exception is propagated.*/
  661.     kMPTaskResumeStepMask        = 1 << kMPTaskResumeStep,        /* The task is resumed and single step is enabled.*/
  662.     kMPTaskResumeBranchMask        = 1 << kMPTaskResumeBranch        /* The task is resumed and branch stepping is enabled.*/
  663. };
  664.  
  665. enum {
  666.                                                                 /* For kMPTaskStateTaskInfo, the task's runState*/
  667.     kMPTaskBlocked                = 0,                            /* Task is blocked (queued on resource)*/
  668.     kMPTaskReady                = 1,                            /* Task is runnable*/
  669.     kMPTaskRunning                = 2                                /* Task is running*/
  670. };
  671.  
  672. enum {
  673.                                                                 /* For kMPTaskStateTaskInfo, the version of the MPTaskInfo structure requested.*/
  674.     kMPTaskInfoVersion            = 2
  675. };
  676.  
  677.  
  678.  
  679. struct MPTaskInfo {
  680.     PBVersion                         version;                    /* Version of the data structure requested*/
  681.  
  682.     OSType                             name;                        /* Task name*/
  683.  
  684.     OSType                             queueName;                    /* Task's queue owner name*/
  685.     UInt16                             runState;                    /* Running, ready, blocked*/
  686.     UInt16                             lastCPU;                    /* Address of CPU where task previously ran*/
  687.     UInt32                             weight;                        /* Processing weight: 1 - 10,000*/
  688.  
  689.     MPProcessID                     processID;                    /* Owning process ID*/
  690.  
  691.     AbsoluteTime                     cpuTime;                    /* Accumulated task time*/
  692.     AbsoluteTime                     schedTime;                    /* Time when last scheduled*/
  693.     AbsoluteTime                     creationTime;                /* Time when task created*/
  694.  
  695.     ItemCount                         codePageFaults;                /* Page faults from code execution*/
  696.     ItemCount                         dataPageFaults;                /* Page faults from data access*/
  697.     ItemCount                         preemptions;                /* Number of times task was preempted*/
  698.  
  699.     MPCpuID                         cpuID;                        /* ID of CPU where task previously ran*/
  700. };
  701. typedef struct MPTaskInfo                MPTaskInfo;
  702. /*
  703.       Upon a task exception, the following message is sent to the designated queue:
  704.       1. The MPTaskID, 
  705.       2. The exception kind. These are enumerated in the interfaces header MachineExceptions.h 
  706.       3. N/A
  707. */
  708.  
  709.  
  710. /* -------------------------------------------------------------------------------------------*/
  711.  
  712. EXTERN_API_C( OSStatus )
  713. MPSetExceptionHandler            (MPTaskID                 task,
  714.                                  MPQueueID                 exceptionQ);
  715.  
  716. EXTERN_API_C( OSStatus )
  717. MPDisposeTaskException            (MPTaskID                 task,
  718.                                  OptionBits             action);
  719.  
  720. EXTERN_API_C( OSStatus )
  721. MPExtractTaskState                (MPTaskID                 task,
  722.                                  MPTaskStateKind         kind,
  723.                                  void *                    info);
  724.  
  725. EXTERN_API_C( OSStatus )
  726. MPSetTaskState                    (MPTaskID                 task,
  727.                                  MPTaskStateKind         kind,
  728.                                  void *                    info);
  729.  
  730. EXTERN_API_C( OSStatus )
  731. MPThrowException                (MPTaskID                 task,
  732.                                  MPExceptionKind         kind);
  733.  
  734. /* -------------------------------------------------------------------------------------------*/
  735.  
  736. EXTERN_API_C( OSStatus )
  737. MPRegisterDebugger                (MPQueueID                 queue,
  738.                                  MPDebuggerLevel         level);
  739.  
  740. EXTERN_API_C( OSStatus )
  741. MPUnregisterDebugger            (MPQueueID                 queue);
  742.  
  743.  
  744.  
  745. /*
  746.    .
  747.    ===========================================================================================
  748.    Remote Call Services
  749.    ====================
  750. */
  751.  
  752. typedef CALLBACK_API_C( void *, MPRemoteProcedure )(void *parameter);
  753.  
  754. typedef UInt8                             MPRemoteContext;
  755. enum {
  756.     kMPAnyRemoteContext            = 0,
  757.     kMPOwningProcessRemoteContext = 1
  758. };
  759.  
  760.  
  761. EXTERN_API_C( void *)
  762. MPRemoteCall                    (MPRemoteProcedure         remoteProc,
  763.                                  void *                    parameter,
  764.                                  MPRemoteContext         context);
  765.  
  766. /* ! MPRemoteCall is new in version 2.0.*/
  767. /*
  768.    .
  769.    ===========================================================================================
  770.    Checking API Availability
  771.    =========================
  772. */
  773.  
  774.  
  775. /*
  776.    ===========================================================================================
  777.    *** WARNING: You must properly check the availability of MP services before calling them!
  778.    ===========================================================================================
  779.    
  780.    Checking for the availability of the MP API is rather ugly.  This is a historical problem,
  781.    caused by the original implementation letting itself get prepared when it really wasn't
  782.    usable and complicated by some important clients then depending on weak linking to "work".
  783.    (And further complicated by CFM not supporting "deferred" imports, which is how many
  784.    programmers think weak imports work.)
  785.    
  786.    The end result is that the MP API library may get prepared by CFM but be totally unusable.
  787.    This means that if you import from the MP API library, you cannot simply check for a
  788.    resolved import to decide if MP services are available.  Worse, if you explicitly prepare
  789.    the MP API library you cannot assume that a noErr result from GetSharedLibrary means that
  790.    MP services are available.
  791.    
  792.    o If you import from the MP API library you MUST:
  793.    
  794.           Use the MPLibraryIsLoaded macro (or equivalent code in languages other than C) to tell
  795.           if the MP API services are available.  It is not sufficient to simply check that an
  796.           imported symbol is resolved as is commonly done for other libraries.  The macro expands
  797.           to the expression:
  798.    
  799.               ( ( (UInt32)_MPIsFullyInitialized != (UInt32)kUnresolvedCFragSymbolAddress ) &&
  800.                 ( _MPIsFullyInitialized () ) )
  801.    
  802.           This checks if the imported symbol _MPIsFullyInitialized is resolved and if resolved
  803.           calls it.  Both parts must succeed for the MP API services to be available.
  804.    
  805.    o If you explicitly prepare the MP API library you MUST:
  806.    
  807.           Use code similar to the following example to tell if the MP API services are available.
  808.           It is not sufficient to depend on just a noErr result from GetSharedLibrary.
  809.    
  810.               OSErr                        err;
  811.               Boolean                        mpIsAvailable            = false;
  812.               CFragConnectionID            connID                    = kInvalidID;
  813.               MPIsFullyInitializedProc    mpIsFullyInitialized    = NULL;
  814.    
  815.               err    = GetSharedLibrary    ( "\pMPLibrary", kCompiledCFragArch, kReferenceCFrag,
  816.                                         &connID, NULL, NULL );
  817.    
  818.               if ( err == noErr ) {
  819.                   err    = FindSymbol    ( connID, "\p_MPIsFullyInitialized",
  820.                                         (Ptr *) &mpIsFullyInitialized, NULL );
  821.               }
  822.    
  823.               if ( err == noErr ) {
  824.                   mpIsAvailable = (* mpIsFullyInitialized) ();
  825.               }
  826.    
  827.    ===========================================================================================
  828. */
  829.  
  830.  
  831. EXTERN_API_C( Boolean )
  832. _MPIsFullyInitialized            (void);
  833.  
  834. typedef CALLBACK_API_C( Boolean , MPIsFullyInitializedProc )(void );
  835. #define MPLibraryIsLoaded()        \
  836.             ( ( (UInt32)_MPIsFullyInitialized != (UInt32)kUnresolvedCFragSymbolAddress ) &&    \
  837.               ( _MPIsFullyInitialized () ) )
  838. /*
  839.    .
  840.    ===========================================================================================
  841.    Miscellaneous Services
  842.    ======================
  843. */
  844.  
  845.  
  846. EXTERN_API_C( void )
  847. _MPLibraryVersion                (const char **            versionCString,
  848.                                  UInt32 *                major,
  849.                                  UInt32 *                minor,
  850.                                  UInt32 *                release,
  851.                                  UInt32 *                revision);
  852.  
  853. /*
  854.    .
  855.    ===========================================================================================
  856.    Unofficial Services
  857.    ===================
  858. */
  859.  
  860.  
  861. /*
  862.    ===========================================================================================
  863.    *** WARNING ***
  864.    These services are not part of the officially documented multiprocessing API.  They may not
  865.    be avaliable in future versions of Mac OS multiprocessing support, or in environments that
  866.    have a different underlying OS architecture such as Mac OS on top of a microkernel, the
  867.    Mac OS Blue Box under Mac OS X, native MP support in Mac OS X, etc.
  868.    ===========================================================================================
  869. */
  870.  
  871. #if CALL_NOT_IN_CARBON
  872. EXTERN_API_C( LogicalAddress )
  873. _MPAllocateSys                    (ByteCount                 size);
  874.  
  875. /* Use MPAllocateAligned instead.*/
  876. EXTERN_API_C( void *)
  877. _MPRPC                            (MPRemoteProcedure         remoteProc,
  878.                                  void *                    parameter);
  879.  
  880. /* Use _MPRemoteCall instead.*/
  881. EXTERN_API_C( Boolean )
  882. _MPTaskIsToolboxSafe            (MPTaskID                 task);
  883.  
  884. #endif  /* CALL_NOT_IN_CARBON */
  885.  
  886. EXTERN_API_C( Boolean )
  887. _MPLibraryIsCompatible            (const char *            versionCString,
  888.                                  UInt32                 major,
  889.                                  UInt32                 minor,
  890.                                  UInt32                 release,
  891.                                  UInt32                 revision);
  892.  
  893.  
  894. #define    MPRPC                    _MPRPC
  895. #define    MPTaskIsToolboxSafe        _MPTaskIsToolboxSafe
  896.  
  897. /*
  898.    .
  899.    ===========================================================================================
  900.    Defunct Services
  901.    ================
  902. */
  903.  
  904. #if CALL_NOT_IN_CARBON
  905. #ifndef MPIncludeDefunctServices
  906. #define MPIncludeDefunctServices 0
  907. #endif  /* !defined(MPIncludeDefunctServices) */
  908.  
  909. #if MPIncludeDefunctServices
  910. EXTERN_API_C( void )
  911. _MPDebugStr                        (ConstStr255Param         msg);
  912.  
  913. EXTERN_API_C( StringPtr )
  914. _MPStatusPString                (OSStatus                 status);
  915.  
  916. EXTERN_API_C( const char *)
  917. _MPStatusCString                (OSStatus                 status);
  918.  
  919.  
  920. #include <stdarg.h>
  921. typedef CALLBACK_API_C( void , MPPrintfHandler )(MPTaskID taskID, const char *format, va_list args);
  922. EXTERN_API_C( void )
  923. _MPInitializePrintf                (MPPrintfHandler         pfn);
  924.  
  925. EXTERN_API_C( void )
  926. _MPPrintf                        (const char *            format,
  927.                                  ...);
  928.  
  929. #endif  /* MPIncludeDefunctServices */
  930.  
  931. #endif  /* CALL_NOT_IN_CARBON */
  932.  
  933. /* ===========================================================================================*/
  934.  
  935.  
  936.  
  937. #if PRAGMA_STRUCT_ALIGN
  938.     #pragma options align=reset
  939. #elif PRAGMA_STRUCT_PACKPUSH
  940.     #pragma pack(pop)
  941. #elif PRAGMA_STRUCT_PACK
  942.     #pragma pack()
  943. #endif
  944.  
  945. #ifdef PRAGMA_IMPORT_OFF
  946. #pragma import off
  947. #elif PRAGMA_IMPORT
  948. #pragma import reset
  949. #endif
  950.  
  951. #ifdef __cplusplus
  952. }
  953. #endif
  954.  
  955. #endif /* __MULTIPROCESSING__ */
  956.  
  957.